<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/resources/js/jquery-1.11.1.min.js"></script>
    <script src="/resources/js/self.js"></script>
    <script type="text/javascript" src="/resources/js/md5.js"></script>
    <script type="text/javascript" src="/resources/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="/resources/js/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/resources/js/tdt.js?r=113"></script>
    <script type="text/javascript" src="/resources/js/Util.js"></script>

</head>
<body>
<div class="row">
    <div class="col-md-12 col-sm-12 col-xs-12">
        <div class="x_panel">
            <div class="x_title">
                <h2>监控维护 <small></small></h2>
                <ul class="nav navbar-right panel_toolbox">

                    <li> <button onclick="back()" class="btn btn-primary" type="button">返回</button>
                    </li>
                </ul>
                <div class="clearfix"></div>
            </div>
            <div class="x_content">
                <br>
                <div id="demo-form2"  class="form-horizontal form-label-left" >
                    <div style="width: 40%;height:100%;float: left">
                        <input type="hidden" name="id" class="form-data" >
                        <div class="form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">名称
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <input type="text" id="name" name="name"
                                       class="form-control form-data col-md-7 col-xs-12" >
                            </div>
                        </div>


                        <div class="form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">监控点编号
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <input type="text" id="videoCode" name="videoCode"
                                       class="form-control form-data col-md-7 col-xs-12" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="longitude">经度
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <input type="text" id="longitude" name="longitude"
                                       class="form-control form-data col-md-7 col-xs-12" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="latitude">纬度
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <input type="text" id="latitude" name="latitude"
                                       class="form-control form-data col-md-7 col-xs-12" >
                            </div>
                        </div>

                        <input type="hidden" name="mapImage" id="mapImage" class="company-data">
                        <input type="hidden" name="bLatitude" id="bLatitude" class="company-data">
                        <input type="hidden" name="bLongitude" id="bLongitude" class="company-data">
                        <input type="hidden" name="eLatitude" id="eLatitude" class="company-data">
                        <input type="hidden" name="eLongitude" id="eLongitude" class="company-data">

                        <div class="ln_solid"></div>
                        <div class="form-group">
                            <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">

                                <button onclick="save()" class="btn btn-success">提交</button>
                                <!--<button onclick="back()" class="btn btn-primary" type="button">返回</button>-->
                            </div>
                        </div>
                    </div>
                    <div style="width: 60%;height:100%;float: right">

                        <div id="allmap" style="min-height: 300px;min-width:400px;height:100%;width:100%;"></div>
                        <div id="searchPanel" style="position: absolute;top:20px;z-index:999;background-color: #fff;margin-left-left: 20px;padding:3px">
                            <input type="text" id="keyWord" value=""/>

                            <!-- 提示词面板 -->
                            <div id="promptDiv" class="prompt"></div>
                            <!-- 统计面板 -->
                            <div id="statisticsDiv" class="statistics"></div>
                            <!-- 建议词面板 -->
                            <div id="suggestsDiv" class="suggests"></div>
                            <!-- 公交提示面板 -->
                            <div id="lineDataDiv" class="lineData"></div>
                            <!-- 搜索结果面板 -->
                            <div id="resultDiv" class="result">
                                <div id="searchDiv"></div>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    var map = null;
    var zoom = 12;
    var marker = null;
    var icon = new T.Icon({
        iconUrl: "/resources/images/web-cam.png",
        iconSize: new T.Point(25, 25),
        iconAnchor: new T.Point(25, 25)
    });
    $(function () {
        initData();
        initMap();
        setImage();
        setTitle("基本信息>监控点");

    });
    function initMap() {
        var imageURL = "http://t0.tianditu.gov.cn/cia_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={x}&TILECOL={y}&tk=611c56de6afcba460edbcbbbd3009445}";
        //创建自定义图层对象
        lay = new T.TileLayer(imageURL, {minZoom: 1, maxZoom: 18});
        var config = {layers: [lay]};
        map = new  T.Map('allmap',config);

        map.setMapType(TMAP_HYBRID_MAP);
        var setLongitude = $("#longitude").val();
        var setlatitude = $("#latitude").val();
        var name = $("#latitude").val();
        if(isNullOrUndefined(name)){
            name ="监控点";
        }
         if(!isNullOrUndefined(setLongitude) &&!isNullOrUndefined(setlatitude) ){
            map.centerAndZoom(new T.LngLat(setLongitude,setlatitude), 22);

            marker = new T.Marker(new T.LngLat(setLongitude,setlatitude), {title: name,icon: icon});
            map.addOverLay(marker);
        }else {
            map.centerAndZoom(new T.LngLat(118.56903,37.57433), zoom);
        }

        map.addEventListener("click",MapClick);
        var ctrl = new T.Control.MapType();
        //添加控件
        map.addControl(ctrl);
        var searchConfig = {
            pageCapacity: 10,	//每页显示的数量
            onSearchComplete: localSearchResult	//接收数据的回调函数
        };
        //创建搜索对象
        localsearch = new T.LocalSearch(map, searchConfig);
        $("#keyWord").keyup(function () {
            bounds = T.LngLatBounds(new T.LngLat(117.84348,37.47577),new T.LngLat(118.1456,37.32085));
            localsearch.searchInBounds(document.getElementById('keyWord').value,bounds);
        });
        $("#keyWord").blur(function () {
            setTimeout("clearSearchPanel ()","800");
        });
    }
    function MapClick(e)

    {
        if(marker !=null){
            map.removeOverLay(marker);
        }

        $("#longitude").val(e.lnglat.getLng());
        $("#latitude").val(e.lnglat.getLat());
        marker = new T.Marker(new T.LngLat(e.lnglat.getLng(),e.lnglat.getLat()), {title: "监控点",icon: icon});
        map.addOverLay(marker);
    }
    function initData(){

        var data = getData();
        var id = data.id;
        var companyId = data.companyId;
        if(null2empty(id) !==""){
            $("input[name='id']").val(id);
            $.ajax({
                url:"/admin/monitorVideo/findWarpper.do",
                data:{'id':id},
                type:'post',
                async:false,
                dataType:'json',
                success:function(data){
                    console.log(data);
                    if(data.success){
                        initPageDate(data.data, '.form-data');
                        initPageDate(data.data, '.company-data');
                    }
                }
            });
            $("#account").attr('readonly','readonly');
        }else {
            $.ajax({
                url:"/admin/company/find.do",
                data:{'id':companyId},
                type:'post',
                async:false,
                dataType:'json',
                success:function(data){
                    console.log(data);
                    if(data.success){
                        initPageDate(data.data, '.company-data');


                    }
                }
            });
        }

    }

    function save() {
        var data = getData();
        var companyId = data.companyId;
        var params = getPageDataByClass("form-data");
        params["companyId"] =companyId;
        if (strIsNull(params['name'])) {
            alert("请输入监控点名称");
            return;
        }
        if (strIsNull(params['videoCode'])) {
            alert("请输入监控点编号");
            return;
        }

        $.ajax({
            url: "/admin/monitorVideo/save.do",
            data: params,
            dataType: 'json',
            type: 'post',
            success: function (data) {
                console.log(data);
                if (data.success) {
                    alert("保存成功");
                    goto("monitor_video_list.html",{"companyId":companyId});
                } else {
                    alert(data.msg);
                }
            }
        });
    }
    function back() {
        var data = getData();
        var companyId = data.companyId;
        goto("monitor_video_list.html",{"companyId":companyId});
    }
    function setImage() {
        var  bLongitude =$("#bLongitude").val();
        var bLatitude = $("#bLatitude").val();
        var eLongitude= $("#eLongitude").val();
        var eLatitude= $("#eLatitude").val();
        var mapImage= $("#mapImage").val();

        if(!isNullOrUndefined(bLongitude) &&
            !isNullOrUndefined(bLatitude)&&
            !isNullOrUndefined(eLongitude)&&
            !isNullOrUndefined(eLatitude)&&
            !isNullOrUndefined(mapImage)){
            var bd = new T.LngLatBounds(
                new T.LngLat(bLongitude, bLatitude),
                new T.LngLat(eLongitude, eLatitude));
            map.setMaxBounds(new T.LngLatBounds(new T.LngLat(bLongitude,bLatitude), new T.LngLat(eLongitude, eLatitude)));
            var imageOverLay = new T.ImageOverlay(mapImage, bd, {
                opacity: 1,
                alt: ""
            });
            map.addOverLay(imageOverLay);
        }
    }
</script>
</html>